package LeetcodeTest_four;
//提莫攻击
public class findPoisonedDuration
{
    public static void main(String[] args)
    {
        int a[]={1,2,3};
        int b=2;
        int result;
        result=solution.findPoisonedDuration(a,b);
        System.out.println(result);
    }
}
class solution
{
    public static int findPoisonedDuration(int[] timeSeries, int duration)
    {
        int i,length,sum;
        i=sum=0;
        length=timeSeries.length;
        if(length==0)
            return 0;
        if (duration==0)
            return 0;
        for (i=0;i<length-1;i++)
        {
            if(timeSeries[i]+duration<=timeSeries[i+1])
                sum+=duration;
            else
                sum+=timeSeries[i+1]-timeSeries[i];
        }
        sum+=duration;
        return sum;
    }
}